package com.knav.inject;

import android.util.Log;

import com.knav.inject.Base.Constant;

import java.lang.reflect.Field;
import java.lang.reflect.Type;


enum ConstantsType {


    INT("int"),
    STRING("java.lang.String"),
    CHAR("char"),
    SHORT("short"),
    BOOLEAN("boolean");

    private String msg ;
    ConstantsType(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return this.msg;
    }
}
public class ConstantsHandle {

    // 处理 constant 注解
    public void DealConstanst(Field field, Constant annotation , Class clazz) {
        Type genericType = field.getGenericType();
        try {
            if (genericType.getTypeName().equals(ConstantsType.STRING.toString())) {
                field.set(clazz.newInstance(), annotation.StringValue());
            } else if (genericType.getTypeName().equals(ConstantsType.INT.toString())) {
                field.set(clazz.newInstance(), annotation.IntegerValue());
            } else if (genericType.getTypeName().equals(ConstantsType.SHORT.toString())) {
                field.set(clazz.newInstance(), annotation.shortValue());
            } else if (genericType.getTypeName().equals(ConstantsType.CHAR.toString())) {
                field.set(clazz.newInstance(), annotation.charValue());
            } else if (genericType.getTypeName().equals(ConstantsType.BOOLEAN.toString())) {
                field.set(clazz.newInstance(), annotation.booleanValue());
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }
}
